$(function () {

})

var vm = new Vue({
    el: '#webpage',
    data: {
        active : '',
        secretId:'',
        secretKey:'',
        envArray:[],
        list : []
    },
    mounted: function () {
        var _this = this;
        $.get(baseURL + "sdk/config/zhibo", function(res){
            if(res.code>0){
                var data = res.data;
                _this.active = data.active;
                _this.secretId = data.secretId;
                _this.secretKey = data.secretKey;
                $.map(data.templateConfig,function (v,k){
                    _this.envArray.push(k);
                    _this.list.push({
                        key:k,
                        value:v
                    });
                });
            }
            console.log(res);
        });
    },
    methods: {
        save:function (){
            var data = {
                active : this.active,
                secretId:this.secretId,
                secretKey:this.secretKey,
                templateConfig : {}
            }
            $.map(this.list,function (value,index){
                data.templateConfig[value.key] = value.value;
            });
            console.log();
            $.post(baseURL + "sdk/config/zhibo",{
                method : 'save',
                active : data.active,
                data : JSON.stringify(data)
            }, function(res) {
                if (res.code > 0) {
                    alert("保存配置成功");
                }else
                {
                    alert(res.msg);
                }
            });
        }
    }
});